home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Q: pointers to pointers that point to structs?
- Date: Sat, 10 Feb 1996 06:08:19 GMT
- Organization: Netcom
- Message-ID: <311c3581.41348295@nntp.ix.netcom.com>
- References: <311C1B4E.217F@mars.superlink.net>
- NNTP-Posting-Host: ix-dc12-17.ix.netcom.com
- X-NETCOM-Date: Fri Feb 09 10:08:17 PM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- Michael Rizzo <rizzom@mars.superlink.net> wrote:
-
- > Hi,
- >
- > I am having trouble dereferencing a pointer to a pointer to a struct.
- > For simplicity just say the struct is:
- > struct test
- > {
- > char teststr[10];
- > int testint;
- > }
- >
- > Now I have a function that just wants to print elements of the
- > structure:
- >
- > void f(test **temp)
- > {
- > printf("%s %d",(please fill in the blank))
- > }
- >
- > How to I get to test.teststr and test.testint from within the funtion.
- > I have tried temp->teststr. I'm still pretty new to programming in C,
- > and the book I'm using does not go into such topics, so any help would
- > be greatly appreciated.
-
- printf("%s %d", (**temp).teststr, (**temp).testint);
-
- or
-
- printf("%s %d", (*temp)->teststr, (*temp)->testint);
-
- The rule to remember is "if x is a pointer to foo, then *x is a foo."
- In your case temp is a pointer to pointer to struct test, so *temp is
- a pointer to struct test and **temp is a struct test. To reference a
- member of a struct, you can use a pointer to struct (e.g., *temp) and
- "->" or a struct (e.g., **temp) and ".".
-
-
- Michael M Rubenstein
-